package com.atguigu.lease.admin.controller.apartment;


import com.atguigu.lease.admin.service.LeaseTermService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.LeaseTerm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/term")
@Tag(name = "租期管理模块")
public class LeaseTermController {
    @Autowired
    LeaseTermService service;

    @GetMapping("/list")
    @Operation(summary = "1,查询所有租期的接口")
    public Result<List<LeaseTerm>> list() {
        return Result.ok(service.list());
    }

    @PostMapping("/saveOrUpdate")
    @Operation(summary = "2,更新与修改租期方式")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm) {
        return Result.ok(service.saveOrUpdate(leaseTerm));
    }

    @DeleteMapping("/deleteById")
    @Operation(summary = "3,根据Id删除租期方式")
    public Result deleteById(
            @Parameter(description = "主键值", in = ParameterIn.QUERY, required = true)
            @RequestParam("id") Integer id) {
        return Result.ok(service.removeById(id));
    }
}
